:header
call %working_dir%\header.cmd

REM 2-Mount.bat
REM This mounts the boot.wim file which is the operating system itself and allows you to edit its settings.
REM Anything you put in this mounted directory will be in the X:\ drive when the pe is booted. There is also a
REM folder called ISO--this is where you want files just on the CD but not in the mounted image.

:WAIK
REM Change DIR to Windows AIK
cd "%waik%\x86\Servicing"

:Main Menu
if defined source Echo Source set to %source%
if defined index ECHO Index set to %index%
if not defined arch-type ECHO The Arch-Type is not set!
if exist "%MOUNTPATH%\Windows" (ECHO An image is already mounted at %MOUNTPATH%) ELSE ECHO No Image Mounted
ECHO.
ECHO -------------------------------------
ECHO              Mount Menu
ECHO -------------------------------------
ECHO.
ECHO 1. Set WIM source
ECHO 2. Select index
ECHO 3. Mount WIM
ECHO 4. Set local server image e.g., ghost, ACME-FS
ECHO Q. Quit to Main Menu
ECHO.
ECHO.

REM ========== Choice Logic ============
choice /c:1234q /n /m "%choice_text%"
if errorlevel 5 goto :end
if errorlevel 4 goto :server
if errorlevel 3 goto :mount
if errorlevel 2 goto :getinfo
if errorlevel 1 goto :clean

:clean
ECHO.
ECHO Cleaing up old mounted WIM files
DISM /Cleanup-Wim
ECHO.
REM Search for wim files in %image_path%
ECHO *************************************************************
ECHO.
ECHO Searching for WIM files in %image_path%
ECHO.
REM **************************************************************
REM Making wims.txt
Echo copy and paste one of the wim file locations back into the prompt >> %working_dir%\wims.txt
Echo. >> %working_dir%\wims.txt
set /a count=1
for /r C:\images %%X in (*.wim) do (call :count_loop "%%X") >> %working_dir%\wims.txt
for /r C:\deploymentshare %%X in (*.wim) do (call :count_loop "%%X") >> %working_dir%\wims.txt

if defined WIM_server (
ECHO.
ECHO *************************************************************
ECHO.
ECHO Searching for WIM files in %WIM_server%\images
for /r \\%WIM_server%\images %%X in (*.wim) do (call :count_loop "%%X") >> %working_dir%\wims.txt
ECHO.
)
REM dir c:\*.wim /b /s
ECHO.
ECHO Type in the full path of your WIM file.
ECHO Example c:\images\x86\windows7.wim
ECHO.
ECHO Leave blank for default location
ECHO Default location is %wim_dest%\winpe.wim
ECHO.
start %working_dir%\wims.txt
set /p source=Path of WIM file: 
if '%source%'=='' set source=%wim_dest%\winpe.wim
del %working_dir%\wims.txt
goto :header

:getinfo
ECHO.
REM Windows Image
dism /get-wiminfo /wimfile:%source%
ECHO.
set /p index=Which Index are you loading: 
goto :header

:mount
ECHO.
ECHO Mounting Image
ECHO Please be patient this may take a while 
DISM /Mount-wim /WimFile:%source% /index:%index% /MountDir:%wim_dest%\mount
goto :header

:server
ECHO.
ECHO Please enter a server name, e.g., ghost, tb-rc
set /p WIM_server=Name of Server: 
goto :header

:count_loop
 echo %count%: %1
 set /a count+=1
 GOTO :eof

:end
call %working_dir%\end.cmd